package com.shanghai.market.plshnaghai.model.measurement;

import com.google.gson.Gson;
import com.shanghai.market.plshnaghai.abstracts.AbstractModelGet;
import com.shanghai.market.plshnaghai.constants.UrlConstants;
import com.shanghai.market.plshnaghai.entity.home.measurement.Quizzes;
import com.shanghai.market.plshnaghai.entity.home.measurement.QuizzesResponse;
import com.shanghai.market.plshnaghai.interfaces.IListView;
import com.shanghai.market.plshnaghai.net.HttpManager;

import java.util.List;

/**
 * Created by Administrator on 2017/8/29.
 */

public class QuizzesModelget extends AbstractModelGet {

    private IListView<Quizzes> view;


    public QuizzesModelget(IListView<Quizzes> view) {
        super();
        this.view = view;
    }

    @Override
    public void getData(String... args) {
        HttpManager manager = HttpManager.getInstance();

        manager.get(UrlConstants.QUESTION_GET, lisenter(), errorListener());
    }

    @Override
    protected void error(String message) {

    }

    @Override
    protected void success(String result) {
        final Gson gson = new Gson();
        QuizzesResponse t = gson.fromJson(result, QuizzesResponse.class);

        String message = t.getErrorMessage();
        final String status = t.getStatus();
        if ("OK".equals(status)) {
            List<Quizzes> quizzes = t.getData();
            view.success(quizzes);

        } else {
            view.failure(message);
        }

    }
}
